<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of reloadtable
 *
 * @author dragon.hu add @2016.5.31
 */


class reloadtables_Controller Extends Controller {
    
    private $areaList; //区号列表
    private $areaAddr2ID; //大区地址到大区ID的映射
    private $wholeServerHost;

    function _init() 
    {
        check_level(50, segment(0), segment(1), segment(2, 'index'));
        
        $config = get_config();
        $this->wholeServerHost = $config['host_url'];

        $server_list=get_server_list();
        foreach($server_list as $k=>$row) {
            $this->areaList[$row['SvrAddr']] = $row['SvrID']."-".$row['SvrName'][1];
            $this->areaAddr2ID[$row['SvrAddr']]=$row['SvrID'];
        }

    }
    
    //put your code here
    function index() {
      if (is_submit()) {
        $rowdata = $_POST ['row'];

        $game_host=$rowdata['area'];
        $rowdata['operator'] = $this->auth->fields['username'];
        $rowdata['inserttime'] = date('Y-m-d H:i:s', time());
        $rowdata['area']=json_encode($rowdata['area']);
        
        $post_data['SessionID']="ewewqw";
        $post_data['SessionKey']="wqqew";

        foreach ($game_host as $key=>$value){
            $post_data['SvrID'] = $this->areaAddr2ID[$value];
            $postResult = vpost($this->wholeServerHost.'update_gamedata',3,json_encode($post_data));
            if ( $postResult ) {
                cp_tips ("success");
            } else {
                $result = translate ( 'C_TIPS_ERROR_TEXT' );
                error ( $result );
            }
        }
        
        if(0 == $postResult)
        {
            $operater = $this->auth->fields['username'];
            insert_log(translate('MENU_SEAL_RELOADTALBES'), 'reload', NULL, array("info"=>"operater = $operater , gm_command = 刷新表格 , area = $areastr"));
            echo "<script>alert('".translate('C_TIPS_SUCCESS_TEXT')."')</script>";
        }
        else
        {
            echo "<script>alert('".translate('C_TIPS_ERROR_TEXT')."')</script>";
        }
      }

      $this->view->assign("arealist", $this->areaList);
      $this->view->display("seal/reloadtables/index"); 
    }
}

?>
